package org.example.springboot3.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.example.springboot3.entity.Album;
import org.example.springboot3.mapper.AlbumMapper;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class AlbumService {
    @Resource
    AlbumMapper albumMapper;
    public PageInfo<Album> selectPage(
    Album album, Integer pageNum, Integer pageSize)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<Album> list = albumMapper.selectAll(album);
        return new PageInfo<>(list);
    }

    public void addPic(Album album) {
        album.setTime(DateUtil.now());
        albumMapper.addPic(album);
    }

    public void deleteById(Integer id) {
        albumMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            this.deleteById(id);
        }
    }

    public void update(Album album) {
        albumMapper.update(album);
    }

    public Album selectById(String time) {
        return albumMapper.selectById(time);
    }

    public List<Album> selectAll(Album album) {
        return albumMapper.selectAll(album);
    }
}//



